home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / B_TERM.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  15KB  |  423 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*          This module was originally written by Vince Perriello           */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                       BinkleyTerm Terminal Module                        */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. void term_Poll (ADDRP);
  51.  
  52. int b_term ()
  53. {
  54.    int j, k;
  55.    int c;
  56.    unsigned int mask = 0xff;
  57.    int gateway_mode = 0;
  58.    int done;
  59.    struct _key_fnc_hdr *OldKeyFncHdr;
  60.    char *autodl = "**\030B00";                   /* Zmodem autodl str.  */
  61.    char *search_autodl = autodl;
  62.    FILE *logfile = NULL;                         /* log file stream
  63.                                                   * descriptor */
  64.    char prot;
  65.    char *p;
  66.  
  67.    int retval = 1;                               /* What to tell the mainline */
  68.    ADDR baddr;
  69.  
  70.    OldKeyFncHdr = KbMapSet (&TrmnlKeyFncHdr);
  71.  
  72.    set_prior(4);                                    /* Always High */
  73.    vfossil_cursor (1);
  74.    done = 0;
  75.    first_block = 0;
  76.    if ((term_init != NULL) && (!CARRIER))
  77.       {
  78.       (void) set_baud (max_baud.rate_value, 0);
  79.       mdm_cmd_string (term_init, 0);                /* then the modem init */
  80.       }
  81.  
  82.    while (!done)
  83.       {
  84.       c = -1;
  85.       if (CHAR_AVAIL ())
  86.          {
  87.          c = MODEM_IN ();
  88.  
  89.          if (comm_bits == BITS_7)
  90.             c &= 0x7f;
  91.  
  92.          /* Check for Zmodem AutoDownload sequence */
  93.          if ((c & 0x7f) == (int) *search_autodl)
  94.             {
  95.             if (!*++search_autodl)
  96.                {
  97.                scr_printf (MSG_TXT(M_ZMODEM_STARTED));
  98.                CLEAR_INBOUND();
  99.  
  100.                (void) Download (NULL, (int)'Z', NULL);
  101.  
  102.                scr_printf (MSG_TXT(M_ZMODEM_FINISHED));
  103.                search_autodl = autodl;
  104.                }
  105.             }
  106.          else search_autodl = autodl;
  107.  
  108. /*
  109.  * I really don't like looking for this piece of crap, but people
  110.  * seem to really want it, so I guess I lose.  Now if only
  111.  * QuickBBS would do things that were ANSI compatible - ugh!
  112.  */
  113.          if (c == ' ')
  114.             {
  115.             screen_clear ();
  116.             }
  117.          else if ((c == ENQ) && (answerback != NULL))
  118.             {
  119.             mdm_cmd_string (answerback, 1);
  120.             }
  121.          else
  122.             {
  123.             WRITE_ANSI ((char)c);
  124.             }
  125.  
  126.          if (logfile != NULL)
  127.             {
  128.             (void) fwrite (&c, 1, 1, logfile);
  129.             }
  130.          }
  131.  
  132.       if (KEYPRESS () || ctrlc_ctr)
  133.          {
  134.          c = 0;
  135.          if (ctrlc_ctr)
  136.             {
  137.             /* We got a ^C, so output it properly */
  138.             while (KEYPRESS ())                  /* Flush keyboard buffer */
  139.                (void) FOSSIL_CHAR ();
  140.             ctrlc_ctr = 0;
  141.             SENDBYTE (3);
  142.             continue;
  143.             }
  144. /* Get the keystroke. Map it, saving the original keystroke. */
  145.  
  146.          k = (int) KbRemap (j = FOSSIL_CHAR ());
  147.  
  148. /* See if it mapped into 'toggle gateway'. If so, do it.     */
  149.  
  150.          if ((unsigned)k == F_TERM_GATEWAYMODE)
  151.             {
  152.             gateway_mode = ~gateway_mode;
  153.             continue;
  154.             }
  155. /*
  156.  * It wasn't 'toggle gateway'. See if it's a command at all.
  157.  * Or if we are currently in gateway mode.
  158.  * 
  159.  * If we are in gateway mode, we will send the raw keystroke
  160.  * out the comm port (zero plus scan code in the case of a
  161.  * function key).
  162.  *
  163.  * Otherwise, we'll send normal keystrokes out verbatim, and
  164.  * apply "ANSI mapping" to function keys.
  165.  */
  166.          if (gateway_mode || ((unsigned)k & F_TERM_BASE) != F_TERM_BASE)
  167.             {
  168.             if (comm_bits == BITS_7)
  169.                mask = 0x7f;
  170.             else mask = 0xff;
  171.  
  172.             if (gateway_mode)
  173.                {
  174.                SENDBYTE ((unsigned char )(c = (j & mask)));
  175.                if (c == 0)
  176.                   SENDBYTE ((unsigned char)(((unsigned int)j >> 8) & mask));
  177.                }
  178.             else
  179.                {
  180.                c = k & mask;
  181.                if (c != 0)
  182.                   SENDBYTE ((unsigned char) c);
  183.                else
  184.                   ansi_map ((unsigned) k);
  185.                }
  186.             continue;
  187.             }
  188. /*
  189.  * It's a command key, which has been remapped to one of our internal
  190.  * codes. Dispatch on it.
  191.  */
  192.          if (!term_overlay (k))
  193.             continue;
  194.       /* else */
  195.          switch ((unsigned)k)
  196.             {
  197.             case F_TERM_CAPTUREFILE:
  198.                if (logfile != NULL)
  199.                   {
  200.                   (void) fclose (logfile);
  201.                   logfile = NULL;
  202.                   (void) sprintf (junk, MSG_TXT(M_LOG_CLOSED), capturename);
  203.                   scr_printf(junk);
  204.                   break;
  205.                   }
  206.  
  207.                if ((logptr == NULL) || (*logptr ==